/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class daiyuyuecw extends HttpServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int i = Integer.parseInt(request.getParameter("i"));

        String data1 = "{\"count\":2,\"list\":[{\"tjrqshijian\":\"2013-12-04\",\"anzhuangdizi\":\"ffffffffffffffffffffffffdsfdsf\",\"kehuming\":\"张锦华\",\"xsdID\":\"BXSD13861262809061\",\"jixing\":\"即热型电热水器\",\"pinpaiming\":\"3M\",\"pgzhuangtai\":\"待预约\",\"wcshijian\":\"\",\"kehuID\":\"15906043148\",\"pgdID\":\"PGD1388026264765\",\"notice\":\"\"},{\"tjrqshijian\":\"2013-12-06\",\"anzhuangdizi\":\"hggggggggggg\",\"kehuming\":\"xql\",\"xsdID\":\"BXSD13862934797653\",\"jixing\":\"即热型电热水器\",\"pinpaiming\":\"3M\",\"pgzhuangtai\":\"待预约\",\"wcshijian\":\"\",\"kehuID\":\"15060897323\",\"pgdID\":\"PGD1397871678299\",\"notice\":\"\"}]}";
        String data2 = "{\"count\":2,\"list\":[{\"tjrqshijian\":\"2013-12-04\",\"anzhuangdizi\":\"ffffffffffffffffffffffffdsfdsf\",\"kehuming\":\"张锦华\",\"xsdID\":\"BXSD13861262809061\",\"jixing\":\"即热型电热水器\",\"pinpaiming\":\"3M\",\"pgzhuangtai\":\"待预约\",\"wcshijian\":\"\",\"kehuID\":\"15906043148\",\"pgdID\":\"PGD1388026264765\",\"notice\":\"\"},{\"tjrqshijian\":\"2013-12-06\",\"anzhuangdizi\":\"hggggggggggg\",\"kehuming\":\"xql\",\"xsdID\":\"BXSD13862934797653\",\"jixing\":\"即热型电热水器\",\"pinpaiming\":\"3M\",\"pgzhuangtai\":\"待预约\",\"wcshijian\":\"\",\"kehuID\":\"15060897323\",\"pgdID\":\"PGD1397871678299\",\"notice\":\"\"}]}";

        String data = "";
        if (i > 5) {

            data = "{\"count\":0,\"list\":[]}";
        } else if (i % 2 != 0) {
            System.out.println(i % 2);
            data = data1;
        } else {
            System.out.println(i % 2);
            data = data2;
        }

        response.setContentType("text/html;charset=gb2312");
        response.setHeader("Access-Control-Allow-Origin", "*");
        try (PrintWriter out = response.getWriter()) {
            out.println(data);
            out.flush();
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
